/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#ifndef LIBS_NETWORK_H
#define LIBS_NETWORK_H

#include <stdint.h>

#define SOCK_STREAM 1
#define SOCK_DGRAM  2
#define AF_INET     2
#define PF_INET     AF_INET

struct in_addr {
    uint32_t s_addr;
};

struct sockaddr {
    unsigned short sa_family;
    char sa_data[14];
};

struct sockaddr_in {
    short          sin_family;
    unsigned short sin_port;
    struct in_addr sin_addr;
    char           sin_zero[8];
};

int             Ssocket(int domain, int type, int protocol);
int             Sbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int             Slisten(int sockfd, int backlog);
int             Saccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int             Sinet_pton(int af, const char *src, void *dst);
const char     *Sinet_ntop(int af, const void *src, char *dst, size_t size);
struct hostent *Sgethostbyname(const char *name);
struct hostent *Sgethostbyaddr(const void *addr, socklen_t len, int type);
int             Sgetaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
void            Sfreeaddrinfo(struct addrinfo *ai);

#endif // LIBS_NETWORK_H